package com.axend.aerosense.dev.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.axend.aerosense.base.bean.BaseBean;
import com.axend.aerosense.base.fragment.MvvmBaseFragment;
import com.axend.aerosense.base.impl.IComplete;
import com.axend.aerosense.base.impl.ILoadDataResult;
import com.axend.aerosense.base.viewmodel.BaseViewModelFactroy;
import com.axend.aerosense.common.bean.RadarBean;
import com.axend.aerosense.dev.BR;
import com.axend.aerosense.dev.R;
import com.axend.aerosense.dev.activity.NewDevSetNetActivity;
import com.axend.aerosense.dev.databinding.DevFragmentWavveInstallConfigBinding;
import com.axend.aerosense.dev.viewmodel.CheckRoomViewModel;
import com.axend.aerosense.dev.viewmodel.DevWavveProConfigViewModel;

/**
 * Wavve Pro安装配置界面
 */
public class DevWavveProInstallConfigFragment
        extends MvvmBaseFragment<DevFragmentWavveInstallConfigBinding, DevWavveProConfigViewModel>
        implements ILoadDataResult<BaseBean> {
    public final static String ARG_PARAM = "RadarBean";
    private RadarBean radarBean;

    public static DevWavveProInstallConfigFragment getInstance() {
        return new DevWavveProInstallConfigFragment();
    }

    public static DevWavveProInstallConfigFragment getInstance(RadarBean radarBean) {
        DevWavveProInstallConfigFragment fragment = new DevWavveProInstallConfigFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ARG_PARAM, radarBean);
        fragment.setArguments(bundle);   //设置参数
        return fragment;
    }

    @Override
    protected void initParameters() {
        super.initParameters();
        Bundle bundle = getArguments();
        if (null != bundle) {
            radarBean = (RadarBean) bundle.getSerializable(ARG_PARAM);
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.dev_fragment_wavve_install_config;
    }

    @Override
    public int getBindingVariable() {
        return BR.model;
    }

    @Override
    protected DevWavveProConfigViewModel getViewModel() {
        BaseViewModelFactroy<BaseBean> factory = new BaseViewModelFactroy<>(this, this);
        DevWavveProConfigViewModel tmp = new ViewModelProvider(this, factory).get(DevWavveProConfigViewModel.class);
        return tmp;
    }

    @Override
    protected void onRetryBtnClick() {

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    private void initView() {
        viewModel.setRadar(radarBean);
        viewModel.angleType.observe(getViewLifecycleOwner(), type->{
            if(type == 0){
                viewDataBinding.devAngleImage.setBackgroundResource(R.mipmap.dev_img_jiaoduyi);
            }else {
                viewDataBinding.devAngleImage.setBackgroundResource(R.mipmap.dev_img_jiaoduer);
            }
        });
        viewModel.installType.observe(getViewLifecycleOwner(), type->{
            if(type == 0){
                viewDataBinding.devWavveImage.setBackgroundResource(R.mipmap.dev_img_side_wall);
                viewDataBinding.devCeiling.setBackgroundResource(R.mipmap.dev_icon_xiding);
                viewDataBinding.devSidewall.setBackgroundResource(R.mipmap.dev_icon_ceqiang1);
                if(viewModel.isWavveSer.getValue()){
                    viewDataBinding.devInstallHeight.setBackgroundResource(R.mipmap.dev_img_installation_height);
                    viewDataBinding.devDistanceWall.setBackgroundResource(R.mipmap.dev_img_dtw);
                }else {
                    viewDataBinding.devInstallHeight.setBackgroundResource(R.mipmap.dev_img_side_wall_lite);
                    viewDataBinding.devDistanceWall.setBackgroundResource(R.mipmap.dev_wall_distance);
                }


            }else {
                viewDataBinding.devWavveImage.setBackgroundResource(R.mipmap.dev_img_ceilling);
                viewDataBinding.devCeiling.setBackgroundResource(R.mipmap.dev_icon_xiding1);
                viewDataBinding.devSidewall.setBackgroundResource(R.mipmap.dev_icon_ceqiang);
                if(viewModel.isWavveSer.getValue()){
                    viewDataBinding.devInstallHeight.setBackgroundResource(R.mipmap.dev_img_install_height);
                    viewDataBinding.devDistanceWall.setBackgroundResource(R.mipmap.dev_img_dtw);
                }else {
                    viewDataBinding.devInstallHeight.setBackgroundResource(R.mipmap.dev_ceiling_height);
                    viewDataBinding.devDistanceWall.setBackgroundResource(R.mipmap.dev_wall_distance);
                }

            }
        });
        viewDataBinding.devAngle1Tvt.setOnClickListener(v->{
            viewModel.angleType.setValue(0);
        });

        viewDataBinding.devAngle2Tvt.setOnClickListener(v->{
            viewModel.angleType.setValue(1);
        });

        viewDataBinding.devSideWallCard.setOnClickListener(v->{
            viewModel.installType.setValue(0);
        });

        viewDataBinding.devCeilingCard.setOnClickListener(v->{
            viewModel.installType.setValue(1);
        });
        setLoadSir(viewDataBinding.devContentView);
        showLoading();
        viewModel.onLoad();
    }

    @Override
    public void loadDataSuccess(BaseBean baseBean) {

    }

    @Override
    public void loadDataFail(String decs) {
        showFailure(decs);
    }

    @Override
    public void onResume() {
        ((NewDevSetNetActivity)getActivity()).setRightTitle(getString(R.string.common_save));
        ((NewDevSetNetActivity)getActivity()).setRightTitleClickable(true);
        ((NewDevSetNetActivity)getActivity()).getCustomToolBar().setSettingTextOnClickListener(v->{
            viewModel.setSettings(getActivity());
        });
        super.onResume();
    }

    @Override
    public void onPause() {
        ((NewDevSetNetActivity)getActivity()).setRightTitle("");
        ((NewDevSetNetActivity)getActivity()).setRightTitleClickable(false);
        super.onPause();
    }
}
